package com.yygo.service.impl;

import com.yygo.dao.MaterialAuditDao;
import com.yygo.model.LoanRequest;
import com.yygo.model.MaterialAudit;
import com.yygo.model.User;
import com.yygo.service.MaterialAuditManager;
import com.yygo.webapp.helper.ExtendedPaginatedList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created by tiansha on 2015/11/20.
 */
@Service("materialAuditManager")
public class MaterialAuditManagerImpl extends GenericManagerImpl<MaterialAudit, Long> implements MaterialAuditManager {

    @Autowired
    private MaterialAuditDao materialAuditDao;

    @Autowired
    public MaterialAuditManagerImpl(MaterialAuditDao materialAuditDao) {
        super(materialAuditDao);
        this.materialAuditDao = materialAuditDao;
    }

    @Override
    public List<LoanRequest> searchSendLoanRequests(User user, String status, Date date, String number, String name,String shipNumber, ExtendedPaginatedList paginatedList) {
        List results = this.materialAuditDao.searchSendLoanRequests(user, status, date, number, name,shipNumber,
                paginatedList.getFirstRecordIndex(), paginatedList.getPageSize(), paginatedList.getSortDirection(), paginatedList.getSortCriterion());
        paginatedList.setList(results);
        paginatedList.setTotalNumberOfRows(materialAuditDao.getSendLoanRequestCount(user, status, date, number, name, shipNumber));
        return results;
    }

    @Override
    public List<LoanRequest> searchReceiveLoanRequests(User user, String shipNumber, ExtendedPaginatedList paginatedList) {
        List results = this.materialAuditDao.searchReceiveLoanRequests(user, shipNumber,
                paginatedList.getFirstRecordIndex(), paginatedList.getPageSize(), paginatedList.getSortDirection(), paginatedList.getSortCriterion());
        paginatedList.setList(results);
        paginatedList.setTotalNumberOfRows(materialAuditDao.getReceiveLoanRequestCount(user, shipNumber));
        return results;
    }

    @Override
    public List<LoanRequest> searchAuditLoanRequests(User user, String number, ExtendedPaginatedList paginatedList) {
        List results = this.materialAuditDao.searchAuditLoanRequests(user, number,
                paginatedList.getFirstRecordIndex(), paginatedList.getPageSize(), paginatedList.getSortDirection(), paginatedList.getSortCriterion());
        paginatedList.setList(results);
        paginatedList.setTotalNumberOfRows(materialAuditDao.getAuditLoanRequestCount(user, number));
        return results;
    }

    @Override
    public List<LoanRequest> searchPrintLoanRequests(User user, String number, ExtendedPaginatedList paginatedList) {
        List results = this.materialAuditDao.searchPrintLoanRequests(user, number,
                paginatedList.getFirstRecordIndex(), paginatedList.getPageSize(), paginatedList.getSortDirection(), paginatedList.getSortCriterion());
        paginatedList.setList(results);
        paginatedList.setTotalNumberOfRows(materialAuditDao.getPrintLoanRequestCount(user, number));
        return results;
    }

}
